package Atop100.huisu;

import java.util.ArrayList;
import java.util.List;

public class Class46 {

     List<List<Integer>>  ans;
     List<Integer> path;
     boolean[] record;
    public List<List<Integer>> permute(int[] nums) {
        ans=new ArrayList<>();
        path=new ArrayList<>();
        record=new boolean[nums.length];
        backTracking(nums,record);
        return  ans;
    }

    public  void  backTracking(int[] nums,boolean[]record){
        if (path.size()== nums.length){
            ans.add(new ArrayList<>(path));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (record[i]){
                continue;
            }else {
                path.add(nums[i] );
                record[i]=true;
                backTracking(nums,record);
                path.remove(path.size()-1);
                record[i]=false;
            }
        }

    }

}
